package com.apartment.own.controller;

import java.util.List;

import com.apartment.own.request.workorder.OwnSysWorkOrderQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.apartment.common.annotation.Log;
import com.apartment.common.core.controller.BaseController;
import com.apartment.common.core.domain.AjaxResult;
import com.apartment.common.enums.BusinessType;
import com.apartment.own.domain.OwnSysWorkOrder;
import com.apartment.own.service.IOwnSysWorkOrderService;
import com.apartment.common.utils.poi.ExcelUtil;
import com.apartment.common.core.page.TableDataInfo;

import javax.validation.Valid;

/**
 * 维修订单Controller
 * 
 * @author @Dog_E
 * @date 2020-08-28
 */
@RestController
@RequestMapping("/own/order")
@Api(value = "工单", tags = "工单")
public class OwnSysWorkOrderController extends BaseController
{
    @Autowired
    private IOwnSysWorkOrderService ownSysWorkOrderService;

    /**
     * 查询维修订单列表
     */
    @PreAuthorize("@ss.hasPermi('own:order:list')")
    @PostMapping("/list")
    @ApiOperation("查询工单返回集合")
    public  TableDataInfo list(@RequestBody(required = false) OwnSysWorkOrderQuery ownSysWorkOrder)
    {
        startPage();
        List<OwnSysWorkOrder> list = ownSysWorkOrderService.selectOwnSysWorkOrderList(ownSysWorkOrder);
        return getDataTable(list);
    }

    /**
     * 导出维修订单列表
     */
    @PreAuthorize("@ss.hasPermi('own:order:export')")
    @Log(title = "维修订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OwnSysWorkOrderQuery ownSysWorkOrder)
    {
        List<OwnSysWorkOrder> list = ownSysWorkOrderService.selectOwnSysWorkOrderList(ownSysWorkOrder);
        ExcelUtil<OwnSysWorkOrder> util = new ExcelUtil<OwnSysWorkOrder>(OwnSysWorkOrder.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 获取维修订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('own:order:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("通过Id查询订单详情")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(ownSysWorkOrderService.selectOwnSysWorkOrderById(id));
    }

    /**
     * 新增维修订单
     */
    @PreAuthorize("@ss.hasPermi('own:order:add')")
    @Log(title = "维修订单", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增维修订单")
    public AjaxResult add(@Valid @RequestBody OwnSysWorkOrderQuery ownSysWorkOrder)
    {
        return toAjax(ownSysWorkOrderService.insertOwnSysWorkOrder(ownSysWorkOrder));
    }

    /**
     * 修改维修订单
     */
    @PreAuthorize("@ss.hasPermi('own:order:edit')")
    @Log(title = "维修订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OwnSysWorkOrder ownSysWorkOrder)
    {
        return toAjax(ownSysWorkOrderService.updateOwnSysWorkOrder(ownSysWorkOrder));
    }

    /**
     * 删除维修订单
     */
    @PreAuthorize("@ss.hasPermi('own:order:remove')")
    @Log(title = "维修订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ownSysWorkOrderService.deleteOwnSysWorkOrderByIds(ids));
    }
}
